using System;
using TMPro;
using UnityEngine;
using UnityEngine.Playables;

public class ProgressChecker : MonoBehaviour
{
    [Header("关卡按钮引用")] [SerializeField] private Transform[] houses;

    [Header("Timeline引用")] [SerializeField]
    private PlayableDirector playableDirector;

    [Header("Path动画引用")] [SerializeField] private UIInitMatPlayer uiInitMatPlayer;
    
    private void OnEnable()
    {
        uiInitMatPlayer.GetMaterial().SetFloat(uiInitMatPlayer.GetPropName(), 0);
        uiInitMatPlayer.enabled = false;
        for (int i = 1; i <= 6; i++)
        {
            if (GameManager.Instance.GetClearance(i))
            {
                houses[i-1].GetChild(0).GetComponent<TMP_Text>().color 
                    = Color.green;
            }
            else
            {
                houses[i-1].GetChild(0).GetComponent<TMP_Text>().color 
                    = Color.white;
            }
        }

        if (!GameManager.Instance.GetHasShowedPrefacePanel())
        {
            PlayTimeline();
            GameManager.Instance.SetHasShowedPrefacePanel(true);
        }
    }

    /*private void Update()
    {
        materials[0].SetFloat("_Locked",0);
    }*/

    public void PlayTimeline()
    {
        playableDirector.Play();
        uiInitMatPlayer.enabled = true;
    }

    /*public void SetStateOfAll()
    {
        SetStateOfAll(true);
    }

    public void SetStateOfAll(bool value)
    {
        foreach (var script in scripts)
        {
            script.enabled = value;
        }
    }*/
}
